﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Text.RegularExpressions;

namespace HDI.Charts2
{
    public class Series : List<Data>
    {

        public string Name
        {
            get;
            private set;
        }

        public Chart Chart;
        public Series(string name)
        {
            this.Name = name;
        }

        public Data this[string name]
        {
            get
            {
                return this.Single(x => x.Name.Equals(name));
            }
        }

        protected string _FName = "";
        public string FName
        {
            get
            {
                if (_FName == "")
                    _FName = Regex.Replace(this.Name, "[^a-zA-Z0-9_]+", "", RegexOptions.Compiled);
                return _FName;

            }
        }

        public Data findData(string name)
        {
            var e = from x in this
                    where x.Name.Equals(name)
                    select x;
            return e.First();
        }

        public Data addData(string name)
        {
            Data tmp = new Data(this);
            tmp.Name = name;
            this.Add(tmp);
            return tmp;
        }

        public Data addData(string name, string value)
        {
            Data tmp = new Data(this);
            tmp.Name = name;
            tmp.Add("Value", value);
            this.Add(tmp);
            return tmp;
        }

        protected Dictionary<String, String> _Options = new Dictionary<string, string>();
        public void setOption(String key, String value)
        {
            if (!_Options.Keys.Contains(key))
            {
                _Options.Add(key, value);
            }
            else
            {
                _Options[key] = value;
            }
        }
        public Dictionary<String, String> Option
        {
            get { return _Options; }
        }

    }
}
